<!DOCTYPE HTML>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title><? echo $title ?></title>
    <? require("lib.php"); ?>
    <link rel="stylesheet" href="css/jquery.datetimepicker.css" type="text/css" media="screen" />
    <script type="text/javascript" src="js/jquery.datetimepicker.js"></script>
</head>
<body>
<div class="content-box"><!-- Start Content Box -->
    <div class="content-box-header">
        <h3><? echo $title ?></h3>
        <div class="clear"></div>
    </div> <!-- End .content-box-header -->
    <div class="content-box-content">
        <?
        switch ($do) {
            case "add":
                add();
                break;
            case "update":
                update($info);
                break;
            case "delete":
                delete($id);
                break;
            default:
                show_info($info);
        }
        ?>
        <? function show_box($row, $iseditmode, $isadd=0){
            global $id, $h, $url, $title, $sales_promotion, $baseurl, $option, $lang, $code_array;
            $name = isset($row['name_'.$lang]) ? $row['name_'.$lang] : '';
            $promotion_id = isset($row['promotion_id']) ? $row['promotion_id'] : '';
            $discount = isset($row['discount']) ? $row['discount'] : '';
            $start_time = isset($row['start_time']) ? $row['start_time'] : '';
            $end_time = isset($row['end_time']) ? $row['end_time'] : '';
            $total = isset($row['total']) ? $row['total'] : '';
            $tag = isset($row['tag']) ? $row['tag'] : '';
            $select = '';
            $enabled = '';
            if($promotion_id){
                $enabled = ' readonly="readonly" ';
            }
            $select .= '<select name="category_id" '.$enabled.'>';
            foreach($code_array['promotion'] as $key => $val){
                $selected = '';
                if($val['id'] == $promotion_id){
                    $selected = 'selected';
                }
                $select .= '<option value="'.$val['id'].'"'.$selected.'>'.$val['name_'.$lang].'</option>';
            }
            $select .= '</select>';

            ?>
            <table width="99%" cellspacing="0" cellpadding="3" class="mbox">
                <tr class="th"><td class="thtitle" width="120" align="right"><? echo $title ?></td>
                    <td><? if(isset($row['id'])) echo $h->hidden('id', iso($row["id"])); ?></td></tr>
                <tr><td class="l"><?=ROOT_SALES_PROMOTION_NAME?></td><td><? echo $h->text('name', $name, 'g') ?></td></tr>
                <tr><td class="l"><?=ROOT_SALES_PROMOTION_CATE?></td><td><?echo $select?></td></tr>
                <tr><td class="l"><?=ROOT_SALES_PROMOTION_START?></td><td><input type="text" value="<?echo $start_time;?>" name="start_time" class="g start_time" />&nbsp;<?=ROOT_EXAMPLE?>: 2012-9-8 9:41:43</td></tr>
                <tr><td class="l"><?=ROOT_SALES_PROMOTION_END?></td><td><input type="text" value="<?echo $end_time;?>" name="end_time" class="g end_time" />&nbsp;<?=ROOT_EXAMPLE?>: 2012-9-8 9:41:43</td></tr>
                <tr><td class="l"><?=ROOT_SALES_PROMOTION_TAG?></td><td><? echo $h->text('tag', $tag, 'g') ?></td></tr>

                <tr><td class="l">&nbsp;</td><td><br><? echo $h->submit('save', '&nbsp; '.ROOT_SAVE.' &nbsp;', $iseditmode==1?'button':'hide') ?>&nbsp;&nbsp;<a onClick="history.go(-1)">[ <?=ROOT_CANCEL?> ]</a><br><br></td></tr>
            </table>
        <? } ?>
        <? function show_boxes($result){
            global $url, $page, $pages, $cateid, $s, $lang, $arrlang, $filter, $sales_promotion, $h, $code_array;
            $str='<table width="99%" class="mlist"><tr>';  // 搜索
            $str.='<td><form action="'.$url.'.php" method="get"><input type="hidden" name="filter" value="'.$filter.'"/><input placeholder="" name="s" class="g" value="'.$s.'" /> &nbsp; <input type="submit" class="button_blue" value=" '.ROOT_SEARCH.' " /></form></td>';
            $str.='<td align="right"><form action="'.$url.'.php" method="get">'.$h->select('filter', $filter, $code_array['sales_promotion'], 'id', 'name_'.$lang, 'g', 'this.form.submit()').'</form></td>';
            $str.='</tr></table>';
            $str.='<table width="99%" cellspacing="0" class="mlist"><tr class="th"><td><strong>'.ROOT_SALES_PROMOTION_NAME.'</strong></td><td><strong>'.ROOT_SALES_PROMOTION_CATE.'</strong></td><td><strong>'.ROOT_SALES_PROMOTION_START.'</strong></td><td><strong>'.ROOT_SALES_PROMOTION_END.'</strong></td><td><a href="'.$url.'.php?do=add">[ '.ROOT_SALES_PROMOTION_ADD.' ]</a></td></tr>';
            $count=1;
            foreach( $result as $row)
            {
                $id=$row['id'];
                $name = $row['name_'.$lang];
                $tem_cate_id=$row['category_id'];
                $tem_cate_tip=ROOT_SALES_PROMOTION_PRODUCT;
                if($tem_cate_id==2)$tem_cate_tip=ROOT_SALES_PROMOTION_CATEGORY;
                $tem_cate = $code_array['promotion'][$row['category_id']]['name_'.$lang];
                $start_time = $row['start_time'];
                $end_time = $row['end_time'];
                $tem_url = 'promotion_discount.php?promotion_id='.$id.'';

                $str.="<tr><td><a href='".$tem_url."'>".$name."</a></td><td>".$tem_cate."</td><td>".$start_time."</td><td>".$end_time."</td><td><a href='".$tem_url."'>".$tem_cate_tip."</a> | <a href=\"$url.php?do=update&id=".$id."\">".ROOT_UPDATE."</a> | <a href=\"$url.php?do=delete&id=".$id."\" onClick=\"javascript: return delc();\">".ROOT_DELETE."</a></td></tr>";
                $count++;
            }
            $str.= "</table>";
            echo $str;
            if($count==1) echo "<br>No data now. (".ROOT_NO_DATA."!)";
            echo echo_page_raw($page, $pages, $url.'.php?filter='.$filter.'&page=');
        } ?>
        <br class="clear" />
    </div> <!-- End .content-box-content -->
    <br class="clear" />
</div><!-- End .content-box -->

<script type="text/javascript">
   $(function(){
	var temlang='<?=$lang=="sc"?"ch":"en"?>';
	$('.start_time').datetimepicker({
		    format:'Y-m-d H:i:s',lang:temlang,
		    onshow:function( ct ){
		        this.setoptions({
			    mindate:'<?=$tomorrow?>'
		    })
	    },
	    timepicker:true
	});
    $('.end_time').datetimepicker({
		    format:'Y-m-d H:i:s',lang:temlang,
//        format:'y-m-d H:i:s',lang:temlang,
		    onshow:function( ct ){
		        this.setoptions({
			    mindate:'<?=$tomorrow?>'
		})
	    },
	    timepicker:true
	});
});
</script>
</body>
</html>
